package com.luke.star.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;

public class AccessTokenUtil {
	private static String filename = "E:\\a_work\\inThePast_codeOfMysefl\\WeixinAuthorizeServlet\\src\\AccessToken.properties";
	public static String getAccessToken(){
		String accessToken = "";
		InputStream in = null;
		try{
			//获取文件流
			Properties props = new Properties();
			in = new FileInputStream(new File(filename));
			props.load(in);
			accessToken = props.getProperty("accessToken");
		}catch(IOException e){
			e.printStackTrace();
		}finally{
			if(in != null){
				try {
					in.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		return accessToken;
	}
	public static void setAccessToken(String accessToken){
		OutputStream out = null;
		try{
			//获取文件流
			Properties props = new Properties();
			out = new FileOutputStream(new File(filename));
			props.setProperty("accessToken", accessToken);//会覆盖
			props.store(out, "AccessToken");
		}catch(IOException e){
			e.printStackTrace();
		}finally{
			if(out != null){
				try {
					out.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}

}
